package com.maoye.ossp.sys.log.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hotent.base.api.query.QueryFilter;
import com.hotent.base.api.query.QueryOP;
import com.maoye.ossp.common.entity.Page;
import com.maoye.ossp.common.web.BaseController;
import com.maoye.ossp.sys.log.entity.SysLogOrgSync;
import com.maoye.ossp.sys.log.service.ISysLogOrgSyncService;

/**
 * 组织同步日志(HR同步日志)Controller
 * @author yanzy
 *
 */
@Controller
@RequestMapping(value = "/sys/log/hr")
public class SysLogOrgSyncController extends BaseController{
	
	@Resource
	private ISysLogOrgSyncService IsysLogOrgSyncService;
	
	/**
	 * 展示组织同步日志
	 * @param sysLogOrgSync
	 * @param model
	 * @param request
	 */
	@RequestMapping(value = "/list")
	public String list(SysLogOrgSync sysLogOrgSync,Model model,HttpServletRequest request){
		QueryFilter queryFilter = getQuerFilter(request, sysLogOrgSync);
		String status = sysLogOrgSync.getStatus();
		if(status!=null){
			if("成功".equals(status)||"成".equals(status)||"功".equals(status)){
				queryFilter.addFilter("status", 1001, QueryOP.EQUAL);
			}
			else if("失败".equals(status)||"失".equals(status)||"败".equals(status)){
				queryFilter.addFilter("status", 1002, QueryOP.EQUAL);
			}
		}
		Page<SysLogOrgSync> page = (Page<SysLogOrgSync>) IsysLogOrgSyncService
				.find(queryFilter);
		model.addAttribute("page", page);
		model.addAttribute("SysLogLogin", sysLogOrgSync);
		return "/sys/log/orgsynclog/list";
	}
	
	/**
	 * 查看单条详细记录
	 * @param id
	 * @param request
	 * @param model
	 */
	@RequestMapping(value = "/{id}/view")
	public String view(@PathVariable String id,HttpServletRequest request,Model model){
		SysLogOrgSync sysLogOrgSync = IsysLogOrgSyncService.getLog(id);
		model.addAttribute("sysLogOrgSync", sysLogOrgSync);
		return "/sys/log/orgsynclog/view";
	}
	
	/**
	 * 删除HR同步日志
	 * @param id
	 * @param request
	 * @param redirectAttributes
	 */
	@RequestMapping(value = "/{id}/remove")
	public String remove(@PathVariable String id,HttpServletRequest request,RedirectAttributes redirectAttributes){
		IsysLogOrgSyncService.expurgateLog(id);
		addMessage(redirectAttributes, "删除日志信息成功！");
		return "redirect:/sys/log/hr/list";
	}
}
